import request from '@/config/axios'

// ERP 采购单 VO
export interface PurPurchaseOrderVO {
  id: number // 编号
  purchaseOrderId: string // 采购单编号-提交供应商采购单编号
  integrateId: string // 一级库整合单编号
  isMainOrder: boolean // 是否主单
  mainOrderId: string // 主单编号
  orderTime: Date // 采购时间
  supplierId: number // 供应商编号
  totalPrice: number // 合计价格
  remark: string // 备注
  status: number // 状态
  processInstanceId: string // 流程实例的编号
}

// ERP 采购单 API
export const PurPurchaseOrderApi = {
  // 查询ERP 采购单分页
  getPurPurchaseOrderPage: async (params: any) => {
    return await request.get({ url: `/erp/pur-purchase-order/page`, params })
  },

  // 查询ERP 采购单详情
  getPurPurchaseOrder: async (id: String) => {
    return await request.get({ url: `/erp/pur-purchase-order/get?id=` + id })
  },

  // 新增ERP 采购单
  createPurPurchaseOrder: async (data: PurPurchaseOrderVO) => {
    return await request.post({ url: `/erp/pur-purchase-order/create`, data })
  },

  // 修改ERP 采购单
  updatePurPurchaseOrder: async (data: PurPurchaseOrderVO) => {
    return await request.put({ url: `/erp/pur-purchase-order/update`, data })
  },

  // 删除ERP 采购单
  deletePurPurchaseOrder: async (id: number) => {
    return await request.delete({ url: `/erp/pur-purchase-order/delete?id=` + id })
  },

  // 导出ERP 采购单 Excel
  exportPurPurchaseOrder: async (params) => {
    return await request.download({ url: `/erp/pur-purchase-order/export-excel`, params })
  },
  // 根据审核单编号 查询采购单
  getPurPurchaseOrderByCheckInvoiceId: async (checkInvoiceId) => {
    return await request.get({ url: `/erp/pur-purchase-order/get-by-check-invoice-id?checkInvoiceId=` + checkInvoiceId })
  },
    // 根据整合单编号 查询采购单
    getPurPurchaseOrderByOrderIntegrateId: async (orderIntegrateId) => {
      return await request.get({ url: `/erp/pur-purchase-order/getPurPurchaseOrderByOrderIntegrateId?orderIntegrateId=` + orderIntegrateId })
    },

// ==================== 子表（ERP 采购单项） ====================

  // 获得ERP 采购单项列表
  getPurPurchaseOrderItemListByPurchaseOrderId: async (purchaseOrderId) => {
    return await request.get({ url: `/erp/pur-purchase-order/pur-purchase-order-item/list-by-purchase-order-id?purchaseOrderId=` + purchaseOrderId })
  },
}
